<!-- Loads initialization file with a couple of variables -->

<%@ include file="inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Registration
		</title>
		<link type="text/css" rel="stylesheet" href="css/main.css">
		<script type="text/javascript" src="js/msg.js"></script>
	</head>
	<body <%
	
		if(request.getParameter("validate") != null)
		{
			/** See if passwords matching otherwise show error message **/
			
			if(!request.getParameter("password").equals(request.getParameter("password2")))
			{
				out.println("onload = \"info(202, 6, " + BASE + ")\"");
			}
			else
			{	
				Applicant a = new Applicant();
				int msg = a.register(request.getParameter("mail"), request.getParameter("password"));
				
				/** See if mail is already stored in database and show error message if so **/
				
				if(msg > 200)
				{
					out.println("onload = \"info(" + msg + ", 6, " + BASE + ")\"");
				}
				else
				{
					response.sendRedirect(BASE + "applicant/index.jsp?msg=" + msg);
				}
			}
		}
	
	%>>
		<div class="header-top"></div>
		<div class="header">
			<a href="index.jsp"><img src="img/logo.png"></a>
		</div>
		<div class="content">
		<div id="message"></div>
		
		<h2>Registration</h2>
		
		Please enter the following information to register.<br><br>
		
		<form method="POST" action="registration.jsp">
			<input type="hidden" name="validate" value="true">
			<table>
				<tr><td>E-Mail:</td><td><input name="mail"></td></tr>
				<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
				<tr><td>Retype Password:</td><td><input type="password" name="password2"></td></tr>
				<tr><td colspan="2" align="right"><input type="submit" value="Register"></td></tr>
			</table>
		</form>
		
		</div>
	</body>
</html>